
#include "OctaveUtils.h"

#include <octave/oct-map.h>

Matrix OctaveUtils::GSLMatrixToOctaveMatrix(const gsl_matrix *M)
{
  Matrix result(M->size1, M->size2);
  
  for(int i = 0; i < M->size1; i++)
    for(int j = 0; j < M->size2; j++)
      result(i, j) = gsl_matrix_get(M, i, j);
  
  return result;
}

ColumnVector OctaveUtils::GSLVectorToOctaveVector(const gsl_vector *v)
{
  ColumnVector result(v->size);
  
  for(int i = 0; i < v->size; i++)
    result(i) = gsl_vector_get(v, i);
  
  return result;
}

gsl_vector *OctaveUtils::OctaveVectorToGSLVector(const ColumnVector &v)
{
  gsl_vector *result = gsl_vector_alloc(v.length());
  
  for(int i = 0; i < v.length(); i++)
    gsl_vector_set(result, i, v(i));
	
  return result;
}
